package com.builder;

import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;

import com.model.Cliente;
import com.model.composite.Contacto;
import com.view.ClienteView;

@ManagedBean
@ViewScoped
@SuppressWarnings("serial")
public class ClienteBuilder extends BaseBuilder<ClienteView, Cliente> {

	@ManagedProperty("#{contactoBuilder}")
	private ContactoBuilder contactoBuilder;

	@ManagedProperty("#{direccionBuilder}")
	private DireccionBuilder direccionBuilder;

	@Override
	public Cliente toDomain(ClienteView view) {
		Cliente unCliente = null;
		if (view!=null){
			unCliente = new Cliente(view.getId(), view.getNombre(),
					view.getNombreFantasia(), view.getObservaciones(),
					contactoBuilder.toDomain(view.getListaContactos()),
					direccionBuilder.toDomain(view.getDireccion()), view.getDni(),
					view.getCuil(), view.getCuit());
		}
		return unCliente;
	}

	@Override
	public ClienteView toView(Cliente model) {
		ClienteView unCliente = null;
		if (model!=null){
			unCliente = new ClienteView(
					model.getID(),
					model.getNombre(),
					model.getNombreFantasia(),
					model.getObservaciones(),
					contactoBuilder.toView(model.getListaContactos() == null ? new ArrayList<Contacto>()
							: model.getListaContactos()),
					direccionBuilder.toView(model.getDireccion()), model.getDni(),
					model.getCuil(), model.getCuit()); 
		}
		return unCliente;
	}

	public ContactoBuilder getContactoBuilder() {
		return contactoBuilder;
	}

	public void setContactoBuilder(ContactoBuilder contactoBuilder) {
		this.contactoBuilder = contactoBuilder;
	}

	public DireccionBuilder getDireccionBuilder() {
		return direccionBuilder;
	}

	public void setDireccionBuilder(DireccionBuilder direccionBuilder) {
		this.direccionBuilder = direccionBuilder;
	}

}
